//
//  YCCoachHomeForStudentViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/25.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  学员看到的教练主页

#import "YCCoachHomeForStudentViewController.h"
#import "YCSessionRightViewButton.h"
#import <FXBlurView/FXBlurView.h>
#import "YCInfoSetupViewController.h"
#import "YCFeedBackViewController.h"//评价与反馈

@interface YCCoachHomeForStudentViewController ()<XHImageViewerDelegate>
/** 头像大背景  */
@property (nonatomic, strong) UIImageView *contentImageView;
/// 导航条左上角
@property (nonatomic,readonly) UIButton *leftNavButton;
/// 导航条右上角
@property (nonatomic,readonly) UIButton *rightNavButton;
/// 头像小背景
@property (nonatomic,readonly) UIImageView *iconBgImageView;
/// 头像
@property (nonatomic,readonly) UIImageView *iconImageView;
/// 昵称
@property (nonatomic,readonly) UILabel *nickerLabel;

/// 教练级别button
@property (nonatomic,readonly) YCSessionRightViewButton *coachGradeButton;
/// 训练场地
@property (nonatomic,readonly) YCSessionRightViewButton *trainPlaceButton;
/// 好评率
@property (nonatomic,readonly) UILabel *rateLabel;
/// 学员满意度
@property (nonatomic,readonly) UILabel *statisfyLabel;


/// 评语
@property (nonatomic,readonly) UILabel *commentLabel;

/** 底部条  */
@property (nonatomic, strong) UIView *bottomView;
/// 发消息
@property (nonatomic,readonly) UIButton *sendMsgButton;
/// 写评价
@property (nonatomic,readonly) UIButton *writeCommentButton;

@property (nonatomic, strong) NSMutableArray *photoArray;
@end

@implementation YCCoachHomeForStudentViewController

@synthesize contentImageView = _contentImageView;
@synthesize leftNavButton = _leftNavButton;
@synthesize rightNavButton = _rightNavButton;
@synthesize nickerLabel = _nickerLabel;
@synthesize coachGradeButton = _coachGradeButton;
@synthesize trainPlaceButton = _trainPlaceButton;
@synthesize rateLabel = _rateLabel;
@synthesize statisfyLabel = _statisfyLabel;
@synthesize commentLabel = _commentLabel;
@synthesize iconBgImageView = _iconBgImageView;
@synthesize iconImageView = _iconImageView;
@synthesize bottomView = _bottomView;
@synthesize sendMsgButton = _sendMsgButton;
@synthesize writeCommentButton = _writeCommentButton;

#pragma mark - 懒加载

- (NSMutableArray *)photoArray
{
    if (!_photoArray) {
        _photoArray = [NSMutableArray array];
    }
    return _photoArray;
}

/// 导航条左边按钮
- (UIButton *)leftNavButton
{
    if(!_leftNavButton)
    {
        _leftNavButton = [[UIButton alloc] init];
        _leftNavButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_leftNavButton setTitle:@"教练" forState:UIControlStateNormal];
        [_leftNavButton addTarget:self action:@selector(didTouchUpInsideLeftNavButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftNavButton;
}

/// 导航条右边按钮
- (UIButton *)rightNavButton
{
    if(!_rightNavButton)
    {
        _rightNavButton = [[UIButton alloc] init];
        _rightNavButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_rightNavButton setImage:[UIImage imageNamed:@"nav_More_white"] forState:UIControlStateNormal];
        [_rightNavButton addTarget:self action:@selector(didTouchUpInsideRightNavButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightNavButton;
}


// 头像
- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        _iconImageView = [[UIImageView alloc] init];
        //        _iconImageView.image = [UIImage imageNamed:@"选择相册"];
        _iconImageView.image = [UIImage imageNamed:@"mf_bg_img"];
        __block CGFloat width = 0;
        [YCAdapter performOtherBlock:^{
            width = 165;
        } IPhone6Block:^{
            width = 195;
        } IPhone6pBlock:^{
            width = 205;
        }];
        _iconImageView.layer.cornerRadius = width / 2.0;
        _iconImageView.layer.masksToBounds = YES;
        _iconImageView.userInteractionEnabled = YES;
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        
        UITapGestureRecognizer *tapIcon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapIcon:)];
        [_iconImageView addGestureRecognizer:tapIcon];
        [self.photoArray addObject:_iconImageView];
    }
    return _iconImageView;
}

// 头像背景
- (UIImageView *)iconBgImageView
{
    if(!_iconBgImageView)
    {
        _iconBgImageView = [[UIImageView alloc] init];
        _iconBgImageView.image = [UIImage imageNamed:@"头像框"];
        _iconBgImageView.userInteractionEnabled = YES;
        _iconBgImageView.layer.masksToBounds = YES;
        __block CGFloat width = 0;
        [YCAdapter performOtherBlock:^{
            width = 190;
        } IPhone6Block:^{
            width = 232;
        } IPhone6pBlock:^{
            width = 240;
        }];
        _iconBgImageView.layer.cornerRadius = width / 2.0;
        _iconBgImageView.contentMode = UIViewContentModeScaleAspectFill;
        _iconBgImageView.clipsToBounds = YES;
    }
    return _iconBgImageView;
}


// 昵称
- (UILabel *)nickerLabel
{
    if(!_nickerLabel)
    {
        _nickerLabel = [[UILabel alloc] init];
        _nickerLabel.text = @"能超";
        _nickerLabel.textColor = [UIColor yc_colorWithUInt:0xffffff alpha:0.9];
        _nickerLabel.textAlignment = NSTextAlignmentCenter;
        _nickerLabel.font = [UIFont systemFontOfSize:15];
    }
    return _nickerLabel;
}

// 好评率
- (UILabel *)rateLabel
{
    if(!_rateLabel)
    {
        _rateLabel = [[UILabel alloc] init];
        _rateLabel.text = @"99.8%";
        _rateLabel.textColor = [UIColor yc_colorWithUInt:0xffffff alpha:1];
        _rateLabel.textAlignment = NSTextAlignmentCenter;
        _rateLabel.font = [UIFont systemFontOfSize:25];
    }
    return _rateLabel;
}

// 学员满意度
- (UILabel *)statisfyLabel
{
    if(!_statisfyLabel)
    {
        _statisfyLabel = [[UILabel alloc] init];
        _statisfyLabel.text = @"学员满意度";
        _statisfyLabel.textColor = [UIColor yc_colorWithUInt:0xffffff alpha:0.9];
        _statisfyLabel.textAlignment = NSTextAlignmentCenter;
        _statisfyLabel.font = [UIFont systemFontOfSize:13];
    }
    return _statisfyLabel;
}


- (YCSessionRightViewButton *)coachGradeButton
{
    if (!_coachGradeButton) {
        _coachGradeButton = [[YCSessionRightViewButton alloc] init];
        [_coachGradeButton setImage:[UIImage imageNamed:@"金牌教练"] forState:UIControlStateNormal];
        [_coachGradeButton setTitle:@"金牌教练" forState:UIControlStateNormal];
        [_coachGradeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    }
    return _coachGradeButton;
}

- (YCSessionRightViewButton *)trainPlaceButton
{
    if (!_trainPlaceButton) {
        _trainPlaceButton = [[YCSessionRightViewButton alloc] init];
        [_trainPlaceButton setImage:[UIImage imageNamed:@"训练场地址"] forState:UIControlStateNormal];
        [_trainPlaceButton setTitle:@"训练场地址" forState:UIControlStateNormal];
        [_trainPlaceButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    }
    return _trainPlaceButton;
}


- (UILabel *)commentLabel
{
    if(!_commentLabel)
    {
        _commentLabel = [[UILabel alloc] init];
        _commentLabel.text = @"真心,细心,耐心,因材施教,科学教学,严谨教学,把好学员考前关.让每一个学员学到真正的驾驶技术和经验,带好每一位学员是我永远不懈的追求.";
        _commentLabel.textColor = [UIColor yc_colorWithUInt:0xffffff];
        _commentLabel.numberOfLines = 0;
        _commentLabel.textAlignment = NSTextAlignmentLeft;
        _commentLabel.font = [UIFont systemFontOfSize:14];
    }
    return _commentLabel;
    
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight-49,kScreenWidth,49)];
        _bottomView.backgroundColor = [UIColor whiteColor];
        UIButton *backBtn = [[UIButton alloc] init];
        [backBtn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
        backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -17, 0, 0);
        [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_bottomView addSubview:backBtn];
        
        // 分隔
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.3];
        [_bottomView addSubview:view];
        
        [_bottomView addSubview:self.sendMsgButton];
        [_bottomView addSubview:self.writeCommentButton];
        
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(_bottomView);
            make.height.equalTo(@35);
            make.width.equalTo(@1);
        }];
        
        [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bottomView);
            make.top.bottom.equalTo(_bottomView);
            make.width.equalTo(@55);
        }];
        
        [self.sendMsgButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_bottomView.mas_centerY);
            make.centerX.equalTo(_bottomView.mas_centerX).offset(-(kScreenWidth/4.0));
            make.height.equalTo(@30);
            make.width.equalTo(@80);
        }];
        
        [self.writeCommentButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_bottomView.mas_centerY);
            make.centerX.equalTo(_bottomView.mas_centerX).offset(kScreenWidth/4.0);
            make.height.equalTo(@30);
            make.width.equalTo(@120);
        }];
        
    }
    return _bottomView;
}


// 发消息
- (UIButton *)sendMsgButton
{
    if (!_sendMsgButton)
    {
        _sendMsgButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sendMsgButton addTarget:self action:@selector(didTouchUpInsideSendMsgButton:) forControlEvents:UIControlEventTouchUpInside];
        _sendMsgButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _sendMsgButton.imageEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
        [_sendMsgButton setImage:[UIImage imageNamed:@"发消息"] forState:UIControlStateNormal];
        [_sendMsgButton setTitle:@"发消息" forState:UIControlStateNormal];
        [_sendMsgButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _sendMsgButton;
}

// 写评价
- (UIButton *)writeCommentButton
{
    if (!_writeCommentButton)
    {
        _writeCommentButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_writeCommentButton addTarget:self action:@selector(didTouchUpInsideWriteCommentButton:) forControlEvents:UIControlEventTouchUpInside];
        _writeCommentButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _writeCommentButton.imageEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
        [_writeCommentButton setImage:[UIImage imageNamed:@"写评价"] forState:UIControlStateNormal];
        _writeCommentButton.imageView.yc_size = CGSizeMake(20, 20);
        _writeCommentButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_writeCommentButton setTitle:@"写评价(132)" forState:UIControlStateNormal];
        [_writeCommentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _writeCommentButton;
}

#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeView];
    [self.coachGradeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.trainPlaceButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}


- (void)makeView
{
    
    UIImageView *contentImageView = [[UIImageView alloc] init];
    contentImageView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    contentImageView.image = [UIImage imageNamed:@"mf_bg_img"];
    contentImageView.userInteractionEnabled = YES;
    //模糊效果
    FXBlurView * aview = [[FXBlurView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    aview.tintColor = [UIColor clearColor];  //前景颜色
    aview.blurRadius = 10;                 //模糊半径，View的模糊效果程度
    [contentImageView addSubview:aview];
    self.contentImageView = contentImageView;
    [self.view addSubview:contentImageView];
    [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
    
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.height.equalTo(@49);
    }];
    
    [self.contentImageView addSubview:self.leftNavButton];
    [self.contentImageView addSubview:self.rightNavButton];
    [self.contentImageView addSubview:self.iconBgImageView];
    [self.contentImageView addSubview:self.iconImageView];
    [self.contentImageView addSubview:self.nickerLabel];
    [self.contentImageView addSubview:self.rateLabel];
    [self.contentImageView addSubview:self.statisfyLabel];
    [self.contentImageView addSubview:self.coachGradeButton];
    [self.contentImageView addSubview:self.trainPlaceButton];
    [self.contentImageView addSubview:self.commentLabel];
    
    
    [self.leftNavButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentImageView).offset(30);
        make.left.equalTo(_contentImageView).offset(15);
        make.height.equalTo(@15);
    }];
    
    [self.rightNavButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentImageView).offset(30);
        make.right.equalTo(_contentImageView).offset(-15);
        make.height.equalTo(@15);
    }];
    
    [_iconBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentImageView).offset(heightFromIphone6Height(70));
        make.centerX.equalTo(self.contentImageView);
        [YCAdapter performOtherBlock:^{
            make.width.height.equalTo(@190);
        } IPhone6Block:^{
            make.width.height.equalTo(@232);
        } IPhone6pBlock:^{
            make.width.height.equalTo(@240);
        }];
    }];
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        [YCAdapter performOtherBlock:^{
            make.width.height.equalTo(@165);
        } IPhone6Block:^{
            make.width.height.equalTo(@195);
        } IPhone6pBlock:^{
            make.width.height.equalTo(@205);
        }];
        make.center.equalTo(_iconBgImageView);
    }];
    
    [_nickerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_iconBgImageView.mas_bottom).offset(heightFromIphone6Height(22));
        make.centerX.equalTo(_iconBgImageView);
        make.height.equalTo(@15);
    }];
    
    [_coachGradeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nickerLabel.mas_bottom).offset(heightFromIphone6Height(20));
        make.centerX.equalTo(_contentImageView);
        make.height.equalTo(@60);
        make.width.equalTo(@80);
    }];
    
    [_trainPlaceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentImageView).offset(-20);
        make.centerY.equalTo(_coachGradeButton);
        make.height.width.equalTo(_coachGradeButton);
    }];
    
    [_rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentImageView).offset(20);
        make.bottom.equalTo(_coachGradeButton.mas_centerY).offset(-5);
        make.width.equalTo(@80);
    }];
    [_statisfyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentImageView).offset(20);
        make.centerY.equalTo(self.coachGradeButton).offset(12.5);//算出来的
        make.width.equalTo(@80);
    }];
    
    [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_coachGradeButton.mas_bottom).offset(20);
        make.left.equalTo(self.contentImageView).offset(15);
        make.right.equalTo(self.contentImageView).offset(-15);
        make.height.equalTo(@80);
    }];
    
    [self.contentImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        //        make.bottom.equalTo(self.commentLabel);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark -
#pragma mark - 点击事件

- (void)didTouchUpInsideLeftNavButton:(UIButton *)button
{
    YCLogFunc
}

- (void)didTouchUpInsideRightNavButton:(UIButton *)button
{
    YCLogFunc
    YCInfoSetupViewController *setupVc = [[YCInfoSetupViewController alloc] init];
    [self.navigationController pushViewController:setupVc animated:YES];
}

// 训练场地
- (void)didTouchUpInsideTrainPlaceButton:(UIButton *)button
{
    YCLogFunc
    
}

#pragma mark - 底部条点击
- (void)backBtnClick:(UIButton *)button
{
    YCLogFunc
    [self.navigationController popViewControllerAnimated:YES];
}
// 发消息
- (void)didTouchUpInsideSendMsgButton:(UIButton *)button
{
    YCLogFunc
}

// 写评价
- (void)didTouchUpInsideWriteCommentButton:(UIButton *)button
{
    YCLogFunc
    YCFeedBackViewController *feedbackVc = [[YCFeedBackViewController alloc] init];
    [self.navigationController pushViewController:feedbackVc animated:YES];
}

// 点击预览大图
- (void)tapIcon:(UITapGestureRecognizer *)gesture
{
    UIImageView *imageView = (UIImageView *)gesture.view;
    YCLogFunc
    
    UIImageView * imgv =[[UIImageView alloc]initWithFrame:imageView.layer.bounds];
    imgv.userInteractionEnabled =YES;
    imgv.contentMode = UIViewContentModeScaleAspectFill;
    imgv.clipsToBounds = YES;
    imgv.image = imageView.image;
    [imageView addSubview:imgv];
    
    XHImageViewer *imageViewer = [[XHImageViewer alloc] init];
    imageViewer.delegate = self;
    [imageViewer showWithImageViews:@[imgv] selectedView:imgv];
    
}

#pragma mark -
- (void)imageViewer:(XHImageViewer *)imageViewer  willDismissWithSelectedView:(UIImageView*)selectedView
{
    YCLogFunc;
}

- (UIView *)customBottomToolBarOfImageViewer:(XHImageViewer *)imageViewer
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - 49, kScreenWidth, 49)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}


@end
